package com.example.myapplication.activity

import android.app.Activity
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import com.example.myapplication.R
import com.example.myapplication.guide.GuideDoubleClickView
import com.example.myapplication.guide.GuideSlideLeftView
import com.example.myapplication.guide.GuideSlideMessageView
import com.example.myapplication.guide.GuideSlideUPView


/**
 * @author: rongfeng
 * @date: 2022/3/10
 * @description
 */
class GuideActivity : AppCompatActivity() {
    private val mHandler = object : Handler(Looper.getMainLooper()) {

    }
    var activity: Activity? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_guide)
        activity = this
//        guideStepSlideMessage()
//        guideSlideUp()
        guideSlideLeft()
//        guideDoubleClick()

    }


    /**
     * 用户引导
     * 左滑清除屏幕消息
     */
    private fun guideStepSlideMessage() {
        mHandler.postDelayed(
            {
                activity?.findViewById<FrameLayout>(android.R.id.content)?.let {
                    val guideSlideMessageView = GuideSlideMessageView(it.context)
                    val layoutParams = FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT
                    )
                    it.addView(
                        guideSlideMessageView, layoutParams
                    )
                    guideSlideMessageView.playAnimation()
                    mHandler.postDelayed({
                        guideSlideMessageView.cancelAnimation()
                        it.removeView(guideSlideMessageView)
                    }, 300000)
                }
            }, 1000
        )
    }


    /**
     * 用户引导
     * 上滑切换直播间
     */
    private fun guideSlideUp() {
        mHandler.postDelayed(
            {
                activity?.findViewById<FrameLayout>(android.R.id.content)?.let {
                    val guideiew = GuideSlideUPView(it.context)
                    val layoutParams = FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT
                    )
                    it.addView(
                        guideiew, layoutParams
                    )
                    guideiew.playAnimation()
                    mHandler.postDelayed({
                        guideiew.cancelAnimation()
                        it.removeView(guideiew)
                    }, 300000)
                }
            }, 1000
        )
    }

    /**
     * 用户引导
     *向左滑动更多直播间
     */
    private fun guideSlideLeft() {
        mHandler.postDelayed(
            {
                activity?.findViewById<FrameLayout>(android.R.id.content)?.let {
                    val guideiew = GuideSlideLeftView(it.context)
                    val layoutParams = FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT
                    )
                    it.addView(
                        guideiew, layoutParams
                    )
                    guideiew.playAnimation()
                    mHandler.postDelayed({
                        guideiew.cancelAnimation()
                        it.removeView(guideiew)
                    }, 300000)
                }
            }, 1000
        )
    }


    /**
     * 用户引导
     *双击屏幕区域为主播打call哦～
     */
    private fun guideDoubleClick() {
        mHandler.postDelayed(
            {
                activity?.findViewById<FrameLayout>(android.R.id.content)?.let {
                    val guideiew = GuideDoubleClickView(it.context)
                    val layoutParams = FrameLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT
                    )
                    it.addView(
                        guideiew, layoutParams
                    )
                    guideiew.playAnimation()
                    mHandler.postDelayed({
                        guideiew.cancelAnimation()
                        it.removeView(guideiew)
                    }, 300000)
                }
            }, 1000
        )
    }


}